package com.taobao.top
{
	import flash.events.Event;
	
	public class TOPItemCats
	{
		public function TOPItemCats()
		{
		}
		
		public function getItemCatsListByParentID(parent_id:String):void
		{
			var topURLLdr:TOPURLLoader = new TOPURLLoader();
			var reqParamArr:Array = new Array();
			reqParamArr=[new TopRequestParam("method","taobao.itemcats.list.get"),new TopRequestParam("parent_cid",parent_cid)];
			topURLLdr.addEventListener(Event.COMPLETE,itemCatsGetHandler);
			topURLLdr.loadData(reqParamArr);
		}
		
		public function getItemCatsListByCid(cid:String):void
		{
			var topURLLdr:TOPURLLoader = new TOPURLLoader();
			var reqParamArr:Array = new Array();
			reqParamArr=[new TopRequestParam("method","taobao.itemcats.list.get"),new TopRequestParam("parent_cid",parent_cid)];
			topURLLdr.addEventListener(Event.COMPLETE,itemCatsGetHandler);
			topURLLdr.loadData(reqParamArr);
		}
		
		public function getItemCatsV2ByParentID(parent_id:String):void
		{
			var topURLLdr:TOPURLLoader = new TOPURLLoader();
			var reqParamArr:Array = new Array();
			reqParamArr=[new TopRequestParam("method","taobao.itemcats.get.v2"),new TopRequestParam("parent_cid",parent_cid)];
			topURLLdr.addEventListener(Event.COMPLETE,itemCatsV2GetHandler);
			topURLLdr.loadData(reqParamArr);
		}
		
		public function getItemCatsV2ByCid(cid:String):void
		{
			var topURLLdr:TOPURLLoader = new TOPURLLoader();
			var reqParamArr:Array = new Array();
			reqParamArr=[new TopRequestParam("method","taobao.itemcats.get.v2"),new TopRequestParam("parent_cid",parent_cid)];
			topURLLdr.addEventListener(Event.COMPLETE,itemCatsV2GetHandler);
			topURLLdr.loadData(reqParamArr);
		}
		
		private function itemCatsGetHandler(event:Event):void
		{
			switch(event.type)
			{
				case Event.COMPLETE:
					var itemCatsArr:Array = itemCatsGetJsonParser(event.target.data);
				break;
				default:
					 dispatchEvent(event.clone());
				break;
			}
		}
		
		private function itemCatsGetJsonParser(jsonStr:String):Array
		{
			if(TOPError.isError(jsonStr))
			{
				var topError:TOPError = TOPError.parseError(jsonStr);
				//dispatchEvent(new ErrorEvent(ErrorEvent.ERROR,false,false,
			}else
			{
				return objToAreasArray((JSON.decode(jsonStr) as Object).rsp);
			}
			return null;
		}
		
		private function itemCatsV2GetHandler(event:Event):void
		{
			
		}
	}
}